<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生信息展示</title>
    <!-- 引入 Vue.js -->
    <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
    <!-- 引入 Axios -->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <style>
        table {
            width: 100%;
            border-collapse: collapse;
        }
        table, th, td {
            border: 1px solid #ddd;
        }
        th, td {
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<div id="app">
    <h1>学生信息展示</h1>
    <table border="1px" width="800px">
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>性别</th>
            <th>手机</th>
            <th>住址</th>
        </tr>
        <tr v-for="stu in students" :key="stu.id">
            <td>{{stu.id}}</td>
            <td>{{stu.name}}</td>
            <td>{{stu.age}}</td>
            <td>{{stu.gender}}</td>
            <td>{{stu.cellphone}}</td>
            <td>{{stu.address}}</td>
        </tr>
    </table>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            students: [], // 学生信息列表

        },
        methods: {
            // 获取所有学生信息
            getAllStudents() {
                axios.get('http://localhost:9999/student/list')
                    .then(response => {
                        if (response.data.status === 1) {
                            this.students = response.data.data.data;
                        }
                    })
                    .catch(error => {
                        console.error('获取学生信息失败:', error);
                    });
            }
        },
        mounted() {
            this.getAllStudents(); // 页面加载时获取所有学生信息
        }
    });
</script>
</body>
</html>